package com.example.demo.base;


/**
 * @author zixiaojun
 * @date 2018/11/12
 * @copyright Moli Teams
 */
public class BaseResponse<T> {

    protected int code;

    protected String message;

    protected Integer total;

    protected T rows;

    public BaseResponse(){
        this(ComStatusCodeEnum.COM_SUCCESS.getCode(), ComStatusCodeEnum.COM_SUCCESS.getMessage());
    }

    public BaseResponse(StatusCode statusCode) {
        this(statusCode.getCode(),statusCode.getMessage());
    }

    public BaseResponse(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getRows() {
        return rows;
    }

    public void setRows(T rows) {
        this.rows = rows;
    }

    public static BaseResponse success(){
        return new BaseResponse(ComStatusCodeEnum.COM_SUCCESS);
    }

    public static BaseResponse error(){
        return new BaseResponse(ComStatusCodeEnum.COM_ERROR);
    }

    public static BaseResponse error(StatusCode statusCode){
        return new BaseResponse(statusCode);
    }
}